package com.demo.common.domain;

import lombok.Builder;
import lombok.Data;
import org.apache.logging.log4j.util.Strings;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author luoguoqiang
 * @since 2020/2/3
 */
@Data
public class ClogDto {

  private String desc;
    private String className;
    private String methodName;
    private Object[] paramList;
    private Date beginDate;
    private long beginTimeMillis;
    private long endTimeMillis;
    private Date endDate;
    private Object returnObj;

    @Override
    public String toString(){
      StringBuilder sb = new StringBuilder();
      sb.append("方法描述:" + (desc == null ? Strings.EMPTY : desc) );
      sb.append("; 调用类:" + (className == null ? Strings.EMPTY : className));
      sb.append("; 调用方法:" + (methodName == null ? Strings.EMPTY : methodName));
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String dateBeginStr = formatter.format(beginDate);
      sb.append("; 调用开始时间:" + dateBeginStr);

      if (endDate != null) {
        String dateEnd = formatter.format(endDate);
        sb.append("; 调用结束时间:" + dateEnd);
        sb.append("; 耗时:" + (endTimeMillis - beginTimeMillis) + "ms");
      }

      for (Object obj : paramList) {
        sb.append("; 参数:" + obj.toString());
      }
      if (returnObj != null) {
        sb.append("; 返回值:" + returnObj);
      }

      return sb.toString();
    }


}
